export const websocketMixins = {
  data(){
    return {
      socket:null,
      socketUrl:''
    }
  },
  created() {
    if("WebSocket" in window) {
      this.socket = new WebSocket(this.socketUrl);
      this.socket.onopen =this.onOpen;
      this.socket.onerror =this.onError;
      this.socket.onclose =this.onClose;
      this.socket.onmessage =this.onMessage;
    } else {
      this.$message.error("该浏览器不支持websocket!");
    }
  },
  methods:{
    onOpen(){},

    // 连接失败
    onError(){
      
    },
    onClose(){},
    onMessage(){}
  }
};
